<template>
  <div>
    <!--清除和发布按钮-->
    <el-row :gutter="10">
      <!--发布按钮-->
      <el-col :span="1.5">
        <el-button type="primary" size="mini" @click="handleRelease">发布</el-button>
      </el-col>
      <!--清除按钮-->
      <el-col :span="1.5">
        <el-button type="danger" size="mini" @click="handleClean">清除</el-button>
      </el-col>
    </el-row>
    <!--主要数据-->
    <el-row :gutter="10" class="mb8" style="width: 1050px">
      <!--左边的树状数据-->
      <el-col :span="12">
        <div class="custom-tree-container">
          <!--暂时先不考虑拖拉拽-->
          <el-tree
              :data="iceShowNode"
              node-key="showConf.nodeId"
              default-expand-all
              @node-click="handleNodeClick"
              :expand-on-click-node="false"
              draggable
              :allow-drag="allowDrag"
              :allow-drop="allowDrop"
              @node-drop="handleDrop"
          >
            <span class="custom-tree-node" slot-scope="{ node, data }">
              <span>
                {{
                  data.showConf.nodeType == 5 ? '◇-' + data.showConf.labelName : data.showConf.nodeType == 6 ? '□-' + data.showConf.labelName : data.showConf.labelName
                }}

                <el-tooltip content="添加子节点" placement="top" effect="light"
                            v-if="data.showConf.nodeType != 5 && data.showConf.nodeType != 6">
                  <el-button
                      type="text"
                      icon="el-icon-circle-plus-outline"

                      @click="() => append(data)">
                </el-button>
              </el-tooltip>

              <el-tooltip content="转换节点" placement="top" effect="light">

                <el-button
                    type="text"
                    icon="el-icon-s-operation"

                    @click="exchange(data)">
                </el-button>
              </el-tooltip>

                <!--添加 v-if 判断 根节点不能删除-->
              <el-tooltip content="删除节点" placement="top"
                          v-if="data.showConf.nodeId != iceShowNode[0].showConf.nodeId "
                          effect="light">
                <el-button

                    type="text"
                    icon="el-icon-delete"

                    @click="remove(data)">

                </el-button>

              </el-tooltip>

              </span>
            </span>

          </el-tree>

        </div>
      </el-col>
     <!--节点修改-->
      <el-col :span="8">

        <el-form :model="currentNode.showConf" ref="showConf" :inline="true" label-width="auto" v-if="JSON.stringify(currentNode) != '{}' && (currentNode.showConf.nodeType == 5 || currentNode.showConf.nodeType == 6)">
          
          <el-form-item label="节点名称">
            <el-input v-model="currentNode.showConf.nodeName" style="width: auto" />
          </el-form-item>

          <el-form-item label="反转">
            <el-switch v-model="currentNode.showConf.inverse" style="width: auto"/>
          </el-form-item>

          <el-form-item label="判断条件" v-if="currentNode.showConf.nodeType == 5">

            <el-select v-model="currentNode.showConf.nodeInfo.hideFields[1].value" placeholder="请选择" style="width: auto" @change="changeFlow" filterable>
              <el-option
                  v-for="item in flowList"
                  :key="item.id"
                  :label="item.flowName"
                  :value="item.databaseName">
              </el-option>
            </el-select>

          </el-form-item>

          <el-form-item label="判断值" v-if="currentNode.showConf.nodeType == 5">
            <el-input v-model="currentNode.showConf.nodeInfo.hideFields[0].value" style="width: auto" v-if="flowType == 'String'"/>

            <el-input type="number" v-model="currentNode.showConf.nodeInfo.hideFields[0].value" style="width: auto" v-if="flowType == 'Number'"/>

            <el-date-picker v-model="currentNode.showConf.nodeInfo.hideFields[0].value" type="datetime" style="width: auto" v-if="flowType == 'Date'" value-format="yyyy-MM-dd HH:mm:ss"/>
          </el-form-item>

          <el-form-item label="单价" v-if="currentNode.showConf.nodeType == 6">
            <el-input type="number" v-model="currentNode.showConf.nodeInfo.iceFields[0].value" style="width: auto"/>
          </el-form-item>

          <el-form-item label="计费字段1" v-if="currentNode.showConf.nodeType == 6">
            <el-select v-model="currentNode.showConf.nodeInfo.iceFields[1].value" placeholder="请选择" style="width: auto" filterable clearable>
              <el-option
                  v-for="item in resultList"
                  :key="item.id"
                  :label="item.resultName"
                  :value="item.databaseName">
              </el-option>
            </el-select>
          </el-form-item>

          <el-form-item label="计费字段2" v-if="currentNode.showConf.nodeType == 6 && currentNode.showConf.confName == 'com.ruoyi.ice.result.AmountResult'">
            <el-select v-model="currentNode.showConf.nodeInfo.iceFields[2].value" placeholder="请选择" style="width: auto" clearable filterable>
              <el-option
                  v-for="item in resultList"
                  :key="item.id"
                  :label="item.resultName"
                  :value="item.databaseName">
              </el-option>
            </el-select>
          </el-form-item>

          <el-form-item label="阶梯字段" v-if="currentNode.showConf.nodeType == 6 && currentNode.showConf.confName == 'com.ruoyi.ice.result.LadderAmount'">
            <el-select v-model="currentNode.showConf.nodeInfo.iceFields[2].value" placeholder="请选择" style="width: auto" filterable>
              <el-option
                  v-for="item in resultList"
                  :key="item.id"
                  :label="item.resultName"
                  :value="item.databaseName">
              </el-option>
            </el-select>
          </el-form-item>

          <el-form-item label="阶梯开始值" v-if="currentNode.showConf.nodeType == 6 && currentNode.showConf.confName == 'com.ruoyi.ice.result.LadderAmount'">
            <el-input type="number" v-model="currentNode.showConf.nodeInfo.iceFields[3].value" style="width: auto"/>
          </el-form-item>

          <el-form-item label="阶梯结束值" v-if="currentNode.showConf.nodeType == 6 && currentNode.showConf.confName == 'com.ruoyi.ice.result.LadderAmount'">
            <el-input type="number" v-model="currentNode.showConf.nodeInfo.iceFields[4].value" style="width: auto"/>
          </el-form-item>

        </el-form>
        
        <div v-else style="width: 300px">
          <span style="visibility:hidden;">1 </span>
        </div>

        <el-button
            type="primary"
            v-if="JSON.stringify(currentNode) != '{}' && (currentNode.showConf.nodeType == 5 || currentNode.showConf.nodeType == 6)"
            size="mini"
            @click="handleEditNode"
        >保存</el-button>

        <el-button
            v-if="JSON.stringify(currentNode) != '{}' && (currentNode.showConf.nodeType == 5 || currentNode.showConf.nodeType == 6)"
            size="mini"
            @click="handleCancelNode">
          取消
        </el-button>

      </el-col>
      
      <el-col :span="4" >
        <SimpleMindMap ref="SimpleMindMap"></SimpleMindMap>
      </el-col>

    </el-row>


    <!--  弹出对话框-->
    <el-dialog :title="title" :visible.sync="open" append-to-body :close-on-click-modal="false" width="450px" @closed="clearForm">

      <el-form :model="form" ref="form" :rules="rule" :inline="true" label-width="100px">

        <el-form-item label="名称" prop="name">

          <el-input v-model="form.name" clearable style="width: 300px" />

        </el-form-item>

        <el-form-item label="节点类型" prop="nodeType">

          <el-select v-model="form.nodeType" style="width: 300px" @change="changeNodeType" filterable>
            <el-option
                v-for="item in nodeTypeList"
                :key="item.value"
                :label="item.label"
                :value="item.value">
            </el-option>
          </el-select>

        </el-form-item>

        <el-form-item label="关系类型" prop="type" v-if="form.nodeType == 4">

          <el-select v-model="form.type" style="width: 300px" filterable>
            <el-option
                v-for="item in typeList"
                :key="item.value"
                :label="item.label"
                :value="item.value">
            </el-option>
          </el-select>

        </el-form-item>

        <el-form-item label="判断节点" prop="flowId" v-if="form.nodeType == 5">

          <el-select v-model="form.databaseName" style="width:300px" placeholder="请选择" @change="changeFlow" filterable>
            <el-option
                v-for="item in flowList"
                :key="item.id"
                :label="item.flowName"
                :value="item.databaseName">
            </el-option>
          </el-select>

        </el-form-item>

        <el-form-item label="节点值" prop="flowValue" v-if="form.nodeType == 5">

          <el-input v-model="form.flowValue" style="width: 300px" v-if="flowType == 'String'"/>

          <el-input type="number" v-model="form.flowValue" style="width: 300px" v-if="flowType == 'Number'"/>

          <el-date-picker v-model="form.flowValue" type="datetime" style="width: 300px" v-if="flowType == 'Date'" value-format="yyyy-MM-dd HH:mm:ss"/>

        </el-form-item>

        <el-form-item label="计费方法" prop="resultType" v-if="form.nodeType == 6">
          <el-select v-model="form.resultType" style="width: 300px" @change="changeResult" filterable>
            <el-option
                v-for="item in resultTypeList"
                :key="item.value"
                :label="item.label"
                :value="item.value">
            </el-option>
          </el-select>
        </el-form-item>

        <el-form-item label="单价" prop="unitPrice" v-if="form.nodeType ==6">

          <el-input type="number" v-model="form.unitPrice" style="width: 300px" />

        </el-form-item>

        <el-form-item label="计费字段1" prop="workNumId" v-if="form.nodeType ==6 && (showAmount || showLadder)">
          <el-select v-model="form.workNumId" style="width: 300px" filterable clearable>
            <el-option v-for="item in resultList" :key="item.id" :label="item.resultName" :value="item.id"/>
          </el-select>
        </el-form-item>

        <el-form-item label="计费字段2" prop="workDaysId" v-if="form.nodeType == 6 && showAmount">
          <el-select v-model="form.workDaysId" style="width: 300px" filterable clearable>
            <el-option v-for="item in resultList" :key="item.id" :label="item.resultName" :value="item.id"/>
          </el-select>
        </el-form-item>

        <el-form-item label="阶梯字段" prop="ladderDaysId" v-if="form.nodeType == 6 && showLadder">
          <el-select v-model="form.ladderDaysId" style="width: 300px" filterable>
            <el-option v-for="item in resultList" :key="item.id" :label="item.resultName" :value="item.id"/>
          </el-select>
        </el-form-item>

        <el-form-item label="阶梯开始值" prop="minValue" v-if="form.nodeType == 6 && showLadder">
          <el-input type="number" v-model="form.minValue" style="width: 300px" />
        </el-form-item>

        <el-form-item label="阶梯结束值" prop="maxValue" v-if="form.nodeType == 6 && showLadder">
          <el-input type="number" v-model="form.maxValue" style="width: 300px" />
        </el-form-item>

        <el-form-item label="反转" prop="inverse" >

          <el-switch v-model="form.inverse" active-value="1" inactive-value="0" style="width: 300px"/>

        </el-form-item>

      </el-form>

      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitForm">确 定</el-button>
        <el-button @click="cancel">取 消</el-button>
      </div>

    </el-dialog>


  </div>

</template>
<script>
import {
  delRules,
  editIceConf,
  exchangeIceConf,
  getIceConf,
  releaseIceConf,
  removeIceConf,
  saveIceConf,
  cleanIceConf, moveIceConf
} from "@/api/contract/rules";
import {labelFlow} from "@/api/base/flow";
import {labelResult} from "@/api/base/result";
import SimpleMindMap from '@/components/SimpleMindMap/Index'
export default {
  name: "iceRules",
  props: ['ruleId'],
  components:{
    SimpleMindMap
  },
  data() {
    return {
      iceShowNode: [],//展示节点

      confBaseId: null,

      nodeTypeList: [
        {label: '关系判断', value: 4},
        {label: '判断条件', value: 5},
        {label: '计费方法', value: 6},
      ],

      timeType:[
        {label:'无限制',value:1},
        {label:'开始时间之后',value:5},
        {label:'结束时间之前',value:6},
        {label:'在时间段内',value:7},
      ],

      typeList:[
        {
          label:'NONE(所有子节点都会执行，无论子节点返回什么，都返回none)',
          value:0,
        },
        {
          label:'AND(所有子节点中，有一个返回false 该节点也将是false，全部是true才是true，在执行到false的地方终止执行，类似于Java的&&)',
          value:1,
        },
        {
          label:'TRUE(所有子节点都会执行，无论子节点返回什么，都返回true，没有子节点也返回true(其他没有子节点返回none)',
          value:2,
        },
        {
          label:'ALL(所有子节点都会执行，有任意一个返回true该节点也是true，没有true有一个节点是false则false，没有true也没有false则返回none，所有子节点执行完毕终止)',
          value:3,
        },
        {
          label:'ANY(所有子节点中，有一个返回true 该节点也将是true，全部false则false，在执行到true的地方终止执行，类似于Java的||)',
          value:4,
        }
      ],

      resultTypeList:[
        {
          label:'标准计费',
          value:'Amount'
        },
        {
          label:'阶梯计费',
          value:'Ladder'
        }
      ],

      flowList: [],

      resultList: [],

      title: '',

      open: false,

      form: {
        uniqueKey:null,
        name: '',
        editType: null,
        nodeType: null,
        type:null,
        selectId: null,
        flowId:null,
        flowValue:null,
        resultType:null,
        inverse:0,
        timeType:1,
        start:null,
        end:null,
        ruleId:null,
        unitPrice:null,
        workNumId:null,
        workDaysId:null,
        ladderDaysId:null,
        minValue:null,
        maxValue:null,
      },

      currentId: null,
      currentUniqueKey:null,
      currentParentId: null,
      currentIndex: null,
      currentNextId: null,

      currentNodeType:null,

      rule: {
        nodeType: [
          {required: true, message: "节点类型不能为空", trigger: "blur"}
        ],
      },

      flowType:'String',

      showAmount:false,
      showLadder:false,

      editType:null,

      showConf:{},

      currentNode:{
        showConf:{
          nodeName:'',
        }
      },

      currentIceId:null,
    }
  },
  created() {
    this.getFlowList()
    this.getResultList()
    this.init();
  },
  methods: {
    handleClean(){
      let query = {
        iceId:this.currentIceId
      }

      this.$modal.confirm('是否回滚修改的数据项？').then(function() {
        

        return cleanIceConf(query)

      }).then(() => {
        this.init();
        this.$emit('ruleChange')

        this.$modal.msgSuccess("回滚成功");
      }).catch(() => {});


    },

    handleRelease(){
      //发布节点
      let query = {
        iceId:this.currentIceId
      }
      releaseIceConf(query).then(res=>{
        if(res && res.code == 200){
          this.$modal.msgSuccess(res.msg)
        }else {
          this.$modal.msgError(res.msg)
        }
      }).finally(()=>{
        this.init()
        this.$emit('ruleChange')
      })
    },

    handleEditNode(){

      //保存修改节点
      let query = {
        iceId:this.currentIceId
      }

      editIceConf(this.currentNode,query).then(res=>{

        if(res && res.code == 200){
          this.$modal.msgSuccess(res.msg)
        }else {
          this.$modal.msgError(res.msg)

        }

      }).finally(()=>{
        // this.currentNode={}
        this.init()
        this.$emit('ruleChange')
      })

    },
    
    handleCancelNode(){
      this.currentNode= {}
      this.init()
    },

    init() {
      getIceConf(this.ruleId).then(res => {
        this.iceShowNode= [];
        // console.log(res)
        this.iceShowNode.push(res.root)
        console.log(this.iceShowNode)
        this.confBaseId = res.root.showConf.nodeId //根节点id
        this.currentIceId = res.iceId//ice id
        this.$refs.SimpleMindMap.mindMapData=this.changeIceShowNodeIntoJson(this.iceShowNode)
      })
    },
    
    handleNodeClick(data) {
      //根据databaseName查找对应的flowList，并将id赋值给flowId
      const matchingItem = this.flowList.find(item => item.databaseName === this.form.databaseName)
      if (matchingItem) {
        this.form.flowId = matchingItem.id
      }

      /* 传值给当前结点 */
      //结点id
      this.currentId = data.showConf.nodeId
      //结点父母结点id
      this.currentParentId = data.parentId

      this.currentIndex = data.index

      this.currentUniqueKey = data.showConf.uniqueKey

      this.currentNextId = data.nextId
      //结点类型
      this.currentNodeType = data.showConf.nodeType

      this.showConf = data.showConf

      this.currentNode = data

      console.log(this.currentNode)

      
      this.form.type=this.currentNode.showConf.nodeType

      //绑定弹出框对应form表单
      this.form.name = data.showConf.nodeName

      this.form.nodeType = data.showConf.nodeType

      if (this.form.nodeType < 4) {
        this.form.nodeType = 4
      }

      this.form.parentId = data.showConf.parentId
      
      /*  将右侧表单的判断条件的Value赋值给form.flowValue*/
      if (this.currentNode.showConf.nodeType === 5 || this.currentNode.showConf.nodeType === 6) {
        this.form.databaseName = this.currentNode.showConf.nodeInfo.hideFields[1].value
        
        /* 将右侧表单的判断值赋值给form.flowValue */
        this.form.flowValue = this.currentNode.showConf.nodeInfo.hideFields[0].value
        this.form.resultType = this.currentNode.showConf.nodeInfo.name
      }

      this.resultTypeList.forEach(item => {
        if (item.label === this.form.resultType) {
          this.form.resultType = item.value
        }
      })

      if (this.form.resultType === 'Amount') {
        this.showAmount = true
      }else if(this.form.resultType==='Ladder'){
        this.showLadder=true
      }

      if (this.currentNode.showConf.nodeType === 6) {
        this.form.unitPrice=this.currentNode.showConf.nodeInfo.iceFields[0].value
        this.form.workNumId=this.currentNode.showConf.nodeInfo.iceFields[1].value
        this.form.workDaysId=this.currentNode.showConf.nodeInfo.iceFields[2].value
        this.form.ladderDaysId=this.currentNode.showConf.nodeInfo.iceFields[2].value

        //根据label查找对应的resultList，并将value赋值给form.resultType,并根据resultType的值给showAmount、showLadder赋值
        if (this.currentNode.showConf.nodeInfo.name === "阶梯计费"){
          this.form.minValue=this.currentNode.showConf.nodeInfo.iceFields[3].value
          this.form.maxValue=this.currentNode.showConf.nodeInfo.iceFields[4].value
        }
      }

      //根据databaseName查找对应的resultList，并将id分别赋值给workNumId、workDaysId、ladderDaysId
      this.resultList.forEach(item=>{
        if(item.databaseName===this.form.workNumId){
          this.form.workNumId=item.id;
        }
        if(item.databaseName===this.form.workDaysId){
          this.form.workDaysId=item.id;
        }
        if (item.databaseName===this.form.ladderDaysId){
          this.form.ladderDaysId=item.id
        }
      })
      //form.flowId=this.currentNode.showConf.bideInfo.hideFields

      this.form.inverse = 0
      
      console.log(this.form)
    },
    
    append(data) {
      // console.log(data);

      //新增 子节点
      this.title = '添加子节点';

      this.open = true

      this.editType = 1


    },

    remove(data){
      // console.log(data);
      let query = {
        selectId: data.showConf.nodeId,
        parentId: data.parentId,
        index: data.index,
        nextId: data.nextId,
        ruleId: this.ruleId
      }
      this.$modal.confirm('是否确认删除ID为"' + data.showConf.nodeId + '"的数据项？').then(function() {

        // console.log(query)

        return removeIceConf(query)

      }).then(() => {
        this.init();

        this.$modal.msgSuccess("删除成功");
      }).catch(() => {});

    },

    exchange(data){
      // console.log(data);
      this.title = '转换节点';
      this.open = true
      this.editType = 5
    },

    cancel(){
      this.open = false
      this.clearForm()
    },

    changeTimeType(data){
      if(data == 1){
        this.form.start = null
        this.form.end = null
      }
      if(data == 5){
        this.form.end = null
      }
      if(data == 6){
        this.form.start = null
      }
    },

    changeResult(data){
      if(data == 'Amount'){
        this.showAmount = true
        this.showLadder = false
      }else if(data == 'Ladder'){
        this.showAmount = false
        this.showLadder = true
      }else {
        this.showLadder = false
        this.showAmount = false
      }
      this.resultTypeList.forEach(item => {
        if (item.label === this.form.resultType) {
          this.form.resultType = item.value
        }
      })
    },

    changeFlow(data){

      //根据 data  遍历 flowList  获取 confType

      this.flowList.forEach(item=>{

        if (item.id == data || item.databaseName == data){

          // console.log(item.confType)

          if (item.id == data || item.databaseName == data) {

            // console.log(item.confType)

            this.flowType = item.confType

          }

        }

      })

      //清空一下节点判断
      // this.form.flowValue = null
      const matchingItem = this.flowList.find(item => item.databaseName === this.form.databaseName)
      if (matchingItem) {
        this.form.flowId = matchingItem.id
      }
    },

    getFlowList(){
      labelFlow().then(res=>{

        this.flowList = res.data

      })
    },

    getResultList(){
      labelResult().then(res=>{

        this.resultList = res.data

      })
    },

    changeNodeType(data) {

      // console.log(data)

      if (data == 5) {

        //获取flowList



      }

      if (data == 6) {

        //获取resultList


      }

    },

    submitForm(){
      this.$refs["form"].validate(valid => {
        if (valid) {
          if (this.editType == 5) {
            //转换节点

            this.form.selectId = this.currentId
            this.form.parentId = this.currentParentId
            this.form.index = this.currentIndex
            this.form.ruleId = this.ruleId

            exchangeIceConf(this.form).then(res => {
              if(res && res.code == 200){

                this.init()
                this.$emit('ruleChange')
                this.open = false

              }else {
                this.$modal.msgError(res.msg)
              }
            })

          } else if(this.editType == 1){
            //新增节点
            this.form.selectId = this.currentId
            this.form.ruleId = this.ruleId
            saveIceConf(this.form).then(res => {
              if(res && res.code == 200){
                // console.log(res)
                this.init()
                this.$emit('ruleChange')
                this.open = false

              }else {
                this.$modal.msgError(res.msg)
              }
            })
          }
        }
      });
    },

    clearForm(){
      this.form.inverse = 0
      this.form.timeType = 1
      this.form.type=0
      this.form.flowId = null
      this.form.flowValue = null
      this.form.unitPrice=null
      this.form.workDaysId=null
      this.form.workNumId=null
      this.form.ladderDaysId=null
      this.form.maxValue=null
      this.form.minValue=null
      this.showAmount = false
      this.showLadder = false
      this.currentNode = {}
    },

    allowDrag(draggingNode) {

      // console.log(draggingNode)

      return draggingNode.data.showConf.nodeId != this.confBaseId;
    },
    allowDrop(draggingNode, dropNode, type) {
      if (dropNode.data.showConf.nodeType === 5 || dropNode.data.showConf.nodeType === 6) {
        return false
      }else {
        return type === 'inner'
      }

    },
    handleDrop(draggingNode, dropNode, dropType, ev) {
      console.log(draggingNode)
      console.log(dropNode)
      console.log(dropType)

      //拉取的nodeId
      let selectId = draggingNode.data.showConf.nodeId
      //原parentId
      let parentId = draggingNode.data.parentId
      //原index
      let index = draggingNode.data.index
      // 新parentId
      let moveToParentId = dropNode.data.showConf.nodeId
      // 新index
      //根据 dropNode.data.sonIds 的长度,用 , 分割
      let sonIds = dropNode.data.sonIds
      let moveTo = 0
      if(sonIds != null){
        let sonIdsArr = sonIds.split(',')
        moveTo = sonIdsArr.length
      }

      let query = {
        iceId: this.currentIceId,
        selectId: selectId,
        parentId: parentId,
        index: index,
        moveToParentId: moveToParentId,
        moveTo: moveTo,
      }

      console.log(query)

      moveIceConf(query).then(res=>{
        if(res && res.code == 200){
          this.$modal.msgSuccess("移动成功")
        }else {
          this.$modal.msgError(res.msg)
        }
      }).finally(()=>{
        this.init()
      })

    },
    
    changeIceShowNodeIntoJson(iceShowNode) {
      var result = {
        "root": {
          "data": {
            "text": "根节点",
            "expand": true,
            "isActive": false
          },
          "children": []
        },
        "theme": {},
        "layout": "logicalStructure",
        "config": {},
        "view": {
          "transform": {
            "scaleX": 1,
            "scaleY": 1,
            "shear": 0,
            "rotate": 0,
            "translateX": -300,
            "translateY": -100,
            "originX": 0,
            "originY": 0,
            "a": 1,
            "b": 0,
            "c": 0,
            "d": 1,
            "e": -300,
            "f": -100
          },
          "state": {
            "scale": 1,
            "x": -300,
            "y": -100,
            "sx": 0,
            "sy": 0
          }
        }}
      result.root.data.text=(iceShowNode[0].showConf.nodeName!=null?iceShowNode[0].showConf.nodeName:"NONE")
      this.dataLoop(iceShowNode[0].children,result.root.children)
      //console.log(result)
      return result
    },

    dataLoop(inChildrenList, resultChildrenList){
      //判断是否有子结点
      if (inChildrenList!=null && inChildrenList.length>0)
      {
        var skipCount = 0 //跳过的判断条件结点的计数变量
        //遍历子结点
        for(var i in inChildrenList){
          //判断是否为判断条件结点
          if (inChildrenList[i].showConf.nodeType==5){
            skipCount++ //若为判断条件结点，则跳过（不push进子结点列表），且skipCount+1
          }else{
            /*  此时该结点非判断条件结点  */
            //判断该子结点是否有子结点
            if (inChildrenList[i].children!=null&&inChildrenList[i].children.length>0){
              var flag=true
              //设置标志变量flag，判断该子结点的所有子结点是否都为判断条件结点
              for(var j in inChildrenList[i].children){
                if (inChildrenList[i].children[j].showConf.nodeType!==5){
                  //检测到非判断条件结点，说明该结点不需要跳过
                  //flag置为false，跳出循环
                  flag=false
                  break
                }
              }
              //若flag为true，说明该结点的所有子结点都为判断条件结点，需要跳过
              //则计数变量skipCount+1
              if (flag){
                skipCount++
              }else{
                /*  此时该结点既不是判断条件结点，也不是所有子结点都为判断条件结点的结点  */
                /*  跳过ANY类型结点 */
                if (inChildrenList[i].showConf.nodeType==4){
                  //当前结点为ANY类型结点时跳过
                  //进行递归
                  this.dataLoop(inChildrenList[i].children,resultChildrenList)
                }else{
                  //当前结点不是ANY类型结点时不跳过
                  resultChildrenList.push({"data":{"text":inChildrenList[i].showConf.nodeName},"children":[]})
                  //进行递归
                  this.dataLoop(inChildrenList[i].children,resultChildrenList[i-skipCount].children)
                }
                
                /*  不跳过ANY类型结点 */
                // resultChildrenList.push({"data":{"text":inChildrenList[i].showConf.nodeName},"children":[]})
                // this.dataLoop(inChildrenList[i].children,resultChildrenList[i-skipCount].children)
              }
            }else{
              /*  此时该结点非判断条件结点，且没有子结点，即非判断条件结点的叶子结点 */
              resultChildrenList.push({"data":{"text":inChildrenList[i].showConf.nodeName},"children":[]})
            }
          }
        }
      }
    },
  }
}
</script>

<style scoped>
.custom-tree-node {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: space-between;
  font-size: 14px;
  padding-right: 8px;
}


</style>
